package util

import (
	"math/rand"
	"time"

	"gitee.com/tonyjia/gb28181/pkg/model/constant"
)

/**
 * @Description
 * @Author lulili
 * @Date 2024/10/22 15:43
 */

func RandString(n int) string {
	rand.Seed(time.Now().UnixNano())
	output := make([]byte, n)
	randomness := make([]byte, n)

	_, err := rand.Read(randomness)
	if err != nil {
		panic(err)
	}
	l := len(constant.LetterBytes)
	for pos := range output {
		random := randomness[pos]
		randomPos := random % uint8(l)
		output[pos] = constant.LetterBytes[randomPos]
	}

	return string(output)
}
